'use strict';
(function (exports) {
    var ChuCards = cc.Layer.extendEX({
        ctor: function (type,pos) {
            this._super();
            this.removeAllChildren();
            this.type = type;
            this.pos = pos;
            return this;
        },
        addCard: function (cardNo, animation, showCard) {
            var smallSize = mCard.getSmallSize();
            var cardSize = mCard.getCardSize();
            if(this.type == 'out'){
                this.Cards =mAction.outCards;
            }else{
                this.Cards =mAction.chuCards;
            }
            var cardList = this.Cards[this.pos];
            cardList.push(cardNo);
            var card = new Card();
            card.setAnchorPoint(0, 1);
            this.addChild(card);
            card.setData(cardNo, null, 2);
            var x = 5;
            var rowIndex = parseInt((cardList.length - 1) / x);
            var colIndex = (cardList.length - 1) % x;
            var pos = null;
            var frompos = null;
            var posH = 360;//cardSize.h*3+5;
            pos = cc.p(colIndex * smallSize.w, rowIndex * -smallSize.h);
            frompos = cc.p(cc.winSize.width / 2 - 270 - smallSize.w / 2, posH);

            // if (this.pos == 1) {
            //     pos = cc.p(- (colIndex * smallSize.w+ smallSize.w/2), rowIndex * smallSize.h+ smallSize.h/2);
            //     frompos = cc.p(cc.winSize.width / 2 + 270 - smallSize.w / 2, posH);
            // } else if (this.pos == 2) {
            //     pos = cc.p(colIndex * smallSize.w+ smallSize.w/2, rowIndex * smallSize.h+ smallSize.h/2);
            //     frompos = cc.p(cc.winSize.width / 2 - 270 - smallSize.w / 2, posH);
            // } else if (this.pos == 0) {
            //     pos = cc.p(-(colIndex * smallSize.w + smallSize.w/2), rowIndex * smallSize.h+ smallSize.h/2);
            //     frompos = cc.p(cc.winSize.width / 2 - smallSize.w / 2, posH);
            // }
            card.setPosition(pos);
            var worldpos = card.convertToWorldSpace(cc.p(0, 0));
            card.setPosition(cc.p(pos.x - (worldpos.x - frompos.x), pos.y - (worldpos.y - frompos.y)));
            if (animation) {
                // if (showCard) {
                //     showCard.runAction(cc.sequence(
                //         cc.delayTime(0.6)
                //         , cc.scaleTo(0.1, 0.01)
                //     ));
                // }
                card.runAction(cc.sequence(
                    cc.delayTime(0.1)
                    , cc.moveTo(0.1, pos.x, pos.y)
                ));
            } else {
                card.setPosition(pos);
            }
            card.setOutCardray();
        },
        resetCard: function () {
            var cardList = this.getChildren();
            for (var i = 0; i < cardList.length; i++) {
                var card = cardList[i];
                card.setData(cardList[i], null, 2);
            }
        },

    });
    exports.ChuCards = ChuCards;
})(window);